package com.vilinno.tlias.controller;

import com.vilinno.tlias.pojo.Emp;
import com.vilinno.tlias.pojo.LoginInfo;
import com.vilinno.tlias.pojo.Result;
import com.vilinno.tlias.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
/**
 * 处理登录请求的controller接口
 */
public class LoginController {

    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private EmpService empService;



    @PostMapping
    public Result login(@RequestBody Emp emp){

        log.info("登录：{}",emp);
        LoginInfo info = empService.login(emp);
        if(info!=null){
            return  Result.success(info);
        }else{
            return Result.error("用户名或密码错误");
        }

    }

}
